import java.util.Scanner;


public class Products {
	static final int N = 100;
	static int map[][];
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int I = sc.nextInt();
		int K = sc.nextInt();
		int T = sc.nextInt();
		
		map = new int[I][I];
		
		for (int test_case = 0; test_case < T; test_case++) {
		for (int i = 0; i < I; i++) {
			for (int j = 0; j < I; j++) {
				map[i][j] = sc.nextInt();
			}
		}
		
		//Find sub matrix
	
		int ans = 0;
		for (int i = 0; i < I; i++) {
			for (int j = 0; j < I; j++) {
				int s = 0;
				for (int i2 = i; i2 < I; i2++) {
					if ((i2 == 0) || i2 == (i+K-1)) {
						for (int j2 = j; j2 < j+K; j2++) {
							s += map[i2][j2];
							System.out.println("Sub: "+map[i2][j2]);
						}
					} else {
						s = s + map[i][j+1] + map[i][j+K-1];
						System.out.println(map[i][j+1]+" "+map[i][j+K-1]);
					}
				}
				if (s > ans) {
					ans =s;
				}
			}
		}
		
		System.out.println("# "+test_case+" "+ans);
		
	}
	}

}
